package com.ysd.controller;



import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Admin;
import com.ysd.service.AdminService;
import com.ysd.util.Result;

@Controller
public class AdminController {
	@Autowired
	AdminService aService;
	@RequestMapping("login2")
	@ResponseBody
	public Object login2(Admin admin,HttpSession session) {
		Admin a=aService.login(admin);
		if (a!=null) {
			if (a.getPassword().equals(admin.getPassword())) {
				session.setAttribute("admin", a);
				return Result.toClient("0", "登陆成功", 0, a);
			} else {
				return Result.toClient("1", "账号或密码错误", 0, null);
			}
		} else {
			return Result.toClient("1", "账号或密码错误", 0, null);
		}
	}
	@RequestMapping("logout")
	 public Object logout(HttpSession session){
	 //清除session
		session.removeAttribute("admin");
		return "";
	 }

}
